using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using ResaGest.Metier.Entite.Chambre;
using ResaGest.DAO;
using ResaGest.Metier.Critere;

namespace ResaGest.DAO
{
    class chambreDAO
    {
        public static List<Chambre> getAllChambreByCritere(ResaGest.Metier.Critere.ChambreCritere critere)
        {
            List<Chambre> lc = new List<Chambre>();
            string sqlCritere = "";
            if (critere.Type_chambre_id != 0)
            {
                sqlCritere += "type_chambre_id = " + critere.Type_chambre_id + " and ";
            }
            if (critere.Taille != 0)
            {
                sqlCritere += "taille = " + critere.Taille + " and ";
            }
            if (critere.Prix_max != 0)
            {
                sqlCritere += "prix_journalier < " + critere.Prix_max + " and ";
            }

            string requete = "";
            requete += sqlCritere != "" ? "select * from Chambre where " + sqlCritere.Substring(0, sqlCritere.LastIndexOf("and")) : "select * from Chambre";


            requSQL requ = new requSQL(requete);
            List<object> list =  requ.getList();
			DataRow dr;
            Chambre ch = new Chambre();
            for (int i = 0; i < list.Count; i++)
            {
                dr = (DataRow) list[i];
                ch.Balcon_chambre = dr["Balcon_chambre"].ToString() == "0" ? false : true;
                ch.Hotel_id = (int)dr["Hotel_id"];
                ch.Id = (int)dr["id_chambre"];
                ch.Lit_id = (int)dr["Lit_id"];
                ch.Occupee = dr["Occupee"].ToString() == "0" ? false : true;
                ch.Prix_journalier =  Convert.ToSingle(dr["Prix_journalier"]);
                ch.Taille = (int)dr["Taille"];
                ch.Type_chambre_id = (int)dr["Type_chambre_id"];
                ch.Type_sdb_id = (int)dr["Type_sbd_id"];
                lc.Add(ch);
                ch = new Chambre();
            }


            return lc;
        }


        public static Chambre getChambreById(int id)
        {
            requSQL requ = new requSQL("select * from chambre where id = " + id);
            List<object> list = requ.getList();
			DataRow dr;
			Chambre ch = new Chambre();
			dr = (DataRow)list[0];
			ch.Balcon_chambre = dr["Balcon_chambre"].ToString() == "0" ? false : true;
			ch.Hotel_id = (int)dr["Hotel_id"];
			ch.Id = (int)dr["id_chambre"];
			ch.Lit_id = (int)dr["Lit_id"];
			ch.Occupee = dr["Occupee"].ToString() == "0" ? false : true;
			ch.Prix_journalier = Convert.ToSingle(dr["Prix_journalier"]);
			ch.Taille = (int)dr["Taille"];
			ch.Type_chambre_id = (int)dr["Type_chambre_id"];
			ch.Type_sdb_id = (int)dr["Type_sbd_id"];
            return ch;
        }

    }
}
